package com.pengshun.modules.api.user.controller;

import com.pengshun.modules.api.coal.validator.First;
import com.pengshun.modules.api.coal.validator.Fourth;
import com.pengshun.modules.api.coal.validator.Second;
import com.pengshun.modules.api.user.service.AccountService;
import com.pengshun.modules.api.user.service.UserBankService;
import com.pengshun.modules.api.user.service.dto.CarOwnerDto;
import com.pengshun.modules.api.user.service.dto.UserBankDto;
import com.pengshun.modules.common.BaseResult;
import com.pengshun.modules.common.PagePara;
import com.pengshun.modules.domain.User;
import com.pengshun.modules.security.Authorization;
import com.pengshun.modules.security.CurrUserInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequiredArgsConstructor
@Api(tags = "银行卡相关")
@RequestMapping("/api/bank")
@ApiIgnore
public class UserBankController {

    private final UserBankService userBankService;

    @ApiOperation(value = "系统银行卡列表")
    @GetMapping(value = "/list", produces = "application/json; charset=utf-8")
    public BaseResult list() throws Exception {
        BaseResult res = userBankService.list();
        return res;
    }
    @ApiOperation(value = "我的银行卡")
    @GetMapping(value = "/myself", produces = "application/json; charset=utf-8")
    @Authorization
    @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    public BaseResult bankList(@ApiIgnore @CurrUserInfo User user) throws Exception {
        BaseResult res = userBankService.bankList(user.getId());
        return res;
    }

    @ApiOperation(value = "添加银行卡")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bankCardNo", value = "银行卡号", dataType = "string",required = true, paramType = "query"),
            @ApiImplicitParam(name = "userName", value = "用户名", dataType = "string",required = true, paramType = "query"),
            @ApiImplicitParam(name = "bankName", value = "银行名称", dataType = "string",required = true, paramType = "query"),
            @ApiImplicitParam(name = "isSelf", value = "0否 1是", dataType = "string",required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @PostMapping(value = "/save")
    @Authorization
    public BaseResult save(@ApiIgnore @CurrUserInfo User user,@ApiIgnore @Validated(value = {Second.class}) UserBankDto para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = userBankService.save(para);
        return res;
    }

    @ApiOperation(value = "删除银行卡")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userBankId", value = "主键id", dataType = "string",required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @PostMapping(value = "/update")
    @Authorization
    public BaseResult update(@ApiIgnore @CurrUserInfo User user,@ApiIgnore @Validated(value = {First.class}) UserBankDto para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = userBankService.update(para);
        return res;
    }
    @ApiOperation(value = "卡号查询银行")
    @ApiImplicitParam(name = "bankCardNo", value = "银行卡号", dataType = "string",required = true, paramType = "query")
    @GetMapping(value = "/name", produces = "application/json; charset=utf-8")
    public BaseResult bank(String bankCardNo) throws Exception {
        BaseResult res = userBankService.bank(bankCardNo);
        return res;
    }

}
